package handler

import "net/http"

// HTTPInterceptor 拦截器
func HTTPInterceptor(h http.HandlerFunc) http.HandlerFunc{

	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		r.ParseForm()
		username := r.Form.Get("username")
		token := r.Form.Get("token")

		// 校验Token是否有效
		if len(username) < 3 || !IsTokenValid(token) {
			w.WriteHeader(http.StatusForbidden)
			return
		}

		// 继续执行
		h(w, r)
	})
}
